#include <bits/stdc++.h>

using namespace std;

int main()
{
    //一般而言，我们喜欢用下表1~n这样在计算的时候直接用[1,n]即可。
    freopen("tree.txt","r",stdin);
    int tree,rangeNum;cin>>tree>>rangeNum;
    vector<vector<int> >op;
    vector<int> treePay(tree+1,0);
    for(int i=0;i<=tree;i++) treePay[i] = 0;
    for(int i=0;i<rangeNum;i++){
        vector<int> temp(3,0);
        cin>>temp[0]>>temp[1]>>temp[2];//from to payment
        op.push_back(temp);
    }

    for(int i=0;i<rangeNum;i++){
        int from = op[i][0], to = op[i][1],x = op[i][2];
        treePay[from+1] = treePay[from+1] + x;
        treePay[to+1+1]  = treePay[to+1+1] - x;
    }

    int sum = 0;
    for(int i=1;i<=tree;i++){
        treePay[i] = treePay[i-1] + treePay[i];
        sum += treePay[i];
    }

    cout<<sum;
    

    return 0;
}

/*
简洁版的代码：
#include <iostream>
using namespace std;
int b[100005];
int main()
{
    int n; //n层
    int m; // m个区间
    cin >> n >> m;

    while (m--)
    {
        int l, r, value;
        cin >> l >> r >> value;
        b[l+1] += value;
        b[r + 1+1] -= value;
    }

    for (int i = 1; i <= n; i++)

        b[i] = b[i] + b[i - 1];

    int sum = 0;

    for (int i = 1; i <= n; i++)
        sum += b[i];
   
    cout << sum << endl;
}
*/